<template>
    <div>
        <img class="headerImg" src="@/assets/img/logo.png" alt="">
        <cube-form :model="model" :schema="schema" @submit="submitHandler">

        </cube-form>
        <a class="to-login" @click="toLogin">去登陆>></a>
    </div>
</template>
<script>
export default {
    name:'Register',
    data() {
        return {
            model:{
                username:'',
                password:'',
            },
            schema:{
                fields:[
                    // 用户名配置
                    {
                        type:'input',
                        modelKey:'username',
                        label:'用户名',
                        props:{
                            placeholder:'请输入用户名',
                        },
                        rules:{
                            // 校验规则
                            required:true,
                            type:'string',
                            min:3,
                            max:15
                        },
                        trigger:'blur',
                        meggages:{
                            required:'用户名不能为空',
                            min:'用户名不能少于3个字符',
                            max:'用户名不能大于15个字符',
                        }
                    },
                    // 密码配置
                    {
                        type:'input',
                        modelKey:'password',
                        label:'密码',
                        props:{
                            placeholder:'请输入密码',
                            type:'password',
                            eye:{
                                open:false
                            }
                        },
                        rules:{
                            // 校验规则
                            required:true,
                        },
                        trigger:'blur',
                        meggages:{
                            required:'密码不能为空',
                        }
                    },
                    {
                        type:'submit',
                        label:'注册'
                    }
                ]
            }
        }
    },
    methods: {
        submitHandler(e){
            e.preventDefault();
            this.$http.get('/api/register',{params:this.model}).then(res=>{
                console.log(res.message)
                console.log(res.success)
                // console.log(res)
            })
        },
        toLogin(){
            this.$router.replace('/login')
        }
    },
}
</script>
<style lang="stylus" scoped>
.to-login{
    display: block;
    height: 100px;
    width: 100px;
    font-size: 16px;
    text-align: center;
    margin: 0 auto;
}
.headerImg{
    display block
    height 150px
    width 100%
}
</style>